<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/08/10 0010
 * Time: 10:54:19
 */
namespace app\admin\Controller;
use app\common\controller\Curt;
use think\Db;

class Collect extends Curt{

    //店铺收藏
    public function getall()
    {
        $where['type']=1;
        $keyword=input('get.keyword');
        if($keyword){
            $where['b.user_realname|c.shop_name']=['like','%'.$keyword.'%'];//模糊查询or可以一个条件中写多个字段以‘|’分开
        }
        $collect=Db::name('collect')->alias('a')
                ->join('ec_user b','a.user_id=b.id')
                ->join('ec_shop c','a.shop_id=c.id')
                ->where($where)
                ->field('a.*,b.user_realname,c.shop_name')
                ->order('a.id desc')
                ->paginate();
        $collects=$collect->toArray();
        $page = $collect->render();
        $this->assign(
            ['collect'=>$collects['data']],
            ['page'=>$page]
        );

    }
    //商品收藏
    public function goodscollect()
    {
        $where['type']=2;
        $keyword=input('get.keyword');
        if($keyword){
            $where['b.user_realname|c.goods_name']=['like','%'.$keyword.'%'];//模糊查询or可以一个条件中写多个字段以‘|’分开
        }
        $collect=Db::name('collect')->alias('a')
            ->join('ec_user b','a.user_id=b.id')
            ->join('ec_goods c','a.goods_id=c.id')
            ->where($where)
            ->field('a.*,b.user_realname,c.goods_name')
            ->order('a.id desc')
            ->paginate();
        $collects=$collect->toArray();
        $page = $collect->render();
        $this->assign(
            ['collect'=>$collects['data']],
            ['page'=>$page]
        );
        return $this->fetch();
    }
    /**
     * 删除商品收藏
     * @param string $id 要删除的id，多个以,分割
     */
    public function goodscollectdel($id)
    {
        $arr = explode(',', $id);
        $i = 0;
        foreach ($arr as $k => $v) {
            if (!$v) {
                continue;
            }
            $this->model->destroy($v,true);
            $i++;
        }
        $this->success('删除' . $i . '条数据', url('goodscollect'));
    }


}